<template>
  <div>
    <el-form-item :label="label">
      <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="changeCheckAll">全选</el-checkbox>
      <el-checkbox-group v-model="aliveValue" @change="changeValue">
        <template v-for="item in list">
          <el-checkbox :label="item.id">
            {{item.title}}
          </el-checkbox>
        </template>
      </el-checkbox-group>
    </el-form-item>
  </div>
</template>
<script>
  export default {
    name: 'ttCheckbox',
    data() {
      return {
        aliveValue: this.value,
        checkAll: false,
        isIndeterminate: true,
        checkAllList: [],
      };
    },
    props: {
      value: [Array],
      list: [Array],
      label: [String],
    },
    mounted() {
      var list = this.list
      for (var index in list) {
        var id = list.id;
        this.checkAllList.push(list[index].id)
      }
    },
    computed: {},
    watch: {},
    methods: {
      changeValue(val){
        this.$emit('input', val);
      },
      changeCheckAll(val) {
        this.aliveValue = val ? this.checkAllList : [];
        this.isIndeterminate = false;
      },
    }
  };
</script>
